<template>
    <div>
        <h1>活动管理修改页面</h1>
        <table class="table table-bordered">
            <tr>
                <td><span>*</span>活动标题</td>
                <td>
                    <input type="text" v-model="w.name">
                </td>
            </tr>
            <tr>
                <td><span>*</span>分类</td>
                <td>
                    <select v-model="w.type">
                        <option value="">请选择</option>
                        <option value="文化娱乐">文化娱乐</option>
                        <option value="体育健身">体育健身</option>
                        <option value="商场活动">商场活动</option>
                        <option value="其他">其他</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td><span>*</span>图片</td>
                <td>
                    <input type="file" @change="Wimage">
                    <img :src="w.photo" alt="" width="100px" height="100px">
                </td>
            </tr>
            <tr>
                <td>活动日期</td>
                <td>
                    <input type="date" v-model="w.startTime">
                    <input type="date" v-model="w.endTime">
                </td>
            </tr>
            <tr>
                <td>报告截止日期</td>
                <td>
                    <input type="date" v-model="w.updateTime">
                </td>
            </tr>
            <tr>
                <td>活动地点</td>
                <td>
                    <input type="text" v-model="w.add">
                </td>
            </tr>

            <tr>
                <td>活动详情</td>
                <td>
                    <textarea v-model="w.speak" rows="3" cols="20">


                    </textarea>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="修改" class="btn btn-primary" @click="wadd">
                </td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import { reactive, toRefs, onMounted } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import axios from 'axios';
import moment from 'moment';

let route = useRoute();
let router = useRouter();
let data: any = reactive({
    w: {
        
  "name": "",
  "type": "",
  "photo": "",
  "startTime": "",
  "endTime": "",
  "add": "",
  "speak": "",
 
  "lastPeople": "李明明",
  
    },
});
let { w } = toRefs(data);
const wadd = () => {
    if (w.value.name == "") {
        alert("请输入活动标题");
        return;
    }
    if (w.value.type == "") {
        alert("请输入活动类型");
        return;
    }
    if (w.value.photo == "") {
        alert("请输入活动图片");
        return;
    }

    let obj = {
        id: route.query.id,
        name: w.value.name,
        type: w.value.type,
        photo: w.value.photo,
        startTime:w.value.startTime,
        endTime: w.value.endTime,
        add: w.value.add,
        speak: w.value.speak,
        
        lastPeople: "李明明",

    }
    axios({
        url: '/api/ActClass/WUpd',
        method: 'put',
        data: obj
    }).then((res) => {
        if (res.data.data > 0) {
            alert('修改成功');
            router.push('/alist')
        }
        else {
            alert('修改失败');
            return;
        }
    })
}

const Wimage = (e: any) => {
    let file = e.target.files[0];
    let formdata = new FormData();
    formdata.append('file', file);
    axios({
        url: '/api/ActClass/AImage',
        method: 'post',
        data: formdata
    }).then((res) => {

        w.value.photo = res.data.data;

    })
}

onMounted(() => {
    Fan();
})
const Fan = () => {
    let obj={
        id:route.query.id
    }
    axios({
        url: '/api/ActClass/FanTain',
        method: 'get',
        params: obj
    }).then((res) => {
        w.value = res.data.data;
    })
}
</script>

<style scoped>
span {
    color: red;
}
</style>